home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / tls / tls044.sh < prev    next >
Encoding:
Text File  |  1994-09-02  |  6.4 KB  |  259 lines

  1. :
  2. #    @(#) postscript 23.3 91/10/07 
  3. #
  4. #    Copyright (C) 1989-1991 The Santa Cruz Operation, Inc.
  5. #        All Rights Reserved.
  6. #    The information in this file is provided for the exclusive use of
  7. #    the licensees of The Santa Cruz Operation, Inc.  Such users have the
  8. #    right to use, modify, and incorporate this code into other products
  9. #    for purposes authorized by the license agreement provided they include
  10. #    this notice and the associated copyright notice with any such product.
  11. #    The information in this file is provided "AS IS" without warranty.
  12. #
  13. #    lp interface for postscript printer
  14. #     arg1 is print job id
  15. #     arg2 is login of user who submitted job
  16. #     arg3 is title ???
  17. #     arg4 is the number of copies to print
  18. #     arg5 is a list of the -o options passed
  19. #     arg6... are paths to files to be printed
  20. #
  21.  
  22. #  Modifications"
  23. #  93/12/19 Terry B. Rhodes (tbr@88open.org)
  24. #
  25. #
  26. #  this program attempts to find a %! (as in %!PS-Adobe) in the
  27. #  first non-blank line of the file.  If it does it assumes the
  28. #  file is raw postscript and prints it as such. Otherwise the
  29. #  file is treated as text and an appropriate postscript header
  30. #  is added.  This all works fine unless the %! doesnt really
  31. #  describe a postscript file or unless you want the actual
  32. #  postscript program to print instead of be interpreted.
  33. #  In these cases you should use the
  34. #
  35. #        -o raw
  36. #
  37. #  option to get textual output of the submitted file.
  38. #
  39. #
  40. #  -o options not supported include , nofilebreak, length, width,
  41. #      lpi, cpi, stty
  42. #
  43. #  this probably should have all these, fonts and other nice options
  44. #  too, wouldn't be too hard to add.
  45. #
  46.  
  47. # usage: FileIsPostscript FILEPATH
  48. #
  49. # if %! appears in the first non-blank line of the file
  50. # we assume the file is a postscript program
  51. # Many programs only scan the first 4 chars of the first line
  52. # this doesnt appear good enough for dos/windows driver output
  53. #
  54. FileIsPostscript()
  55. {
  56. Z="`awk <$1 2>/dev/null '
  57.    {
  58.    if ( NF < 1)
  59.       { next; }
  60.    if ( index($0, "%!") != 0 )
  61.       { printf("true"); }
  62.    exit
  63.    }
  64. '`"
  65. $DEBUG && awk <$1 2>/dev/null '
  66.    {
  67.     print $0
  68.    if ( NF < 1)
  69.       { next; }
  70.    if ( index($0, "%!") != 0 )
  71.       { printf("true"); }
  72.    exit
  73.    }
  74. ' >>/tmp/$PRINTER.out
  75.  
  76. [ "$Z" = "true" ] && return 0
  77. return 1
  78. }
  79.  
  80.  
  81.  
  82. PrintBannerPages()
  83. {
  84. # nhead gets the value of BANNERS or 1 by default
  85. nhead=`sed -n 's/^BANNERS=//p' /etc/default/lpd`
  86. [ "$nhead" -eq 0 ] && nhead=1
  87. [ "$nhead" -gt 5 ] && nhead=0
  88.  
  89. if [ "$nhead" -gt 0 ]
  90. then
  91.     # get the local system id
  92.     if test -r /etc/systemid
  93.     then
  94.         sysid=`sed 1q /etc/systemid`
  95.     else
  96.         sysid=`uname -n`
  97.     fi
  98.         
  99.     # user = fifth field of /etc/passwd
  100.     user=`sed -n "s/^$USER:.*:.*:.*:\(.*\):.*:.*$/\1/p" /etc/passwd`
  101.     # todays date
  102.     tdate=`date`
  103.     
  104.     while [ "$nhead" -gt 0 ]
  105.     do
  106.         echo "%!"
  107.         echo "/i{72 mul}def"
  108.         echo "/m{moveto}def"
  109.         echo "/s{show}def"
  110.         echo "/o{true charpath stroke}def"
  111.         echo "/rct{moveto dup neg 3 1 roll 0 exch rlineto"
  112.         echo "  0 rlineto 0 exch rlineto closepath}def"
  113.         echo "6.5 i 1.1 i 0.95 i 8.9 i rct 0.0 setgray stroke"
  114.         echo "6.5 i 1.1 i 0.95 i 8.9 i rct 0.8 setgray fill"
  115.         echo "/Helvetica-Bold findfont 45 scalefont setfont"
  116.         echo "1.0 setgray ($USER) 1.0 i 9.5 i m s"
  117.         echo "0.0 setgray ($USER) 1.0 i 9.5 i m o"
  118.         echo "/Helvetica findfont 20 scalefont setfont"
  119.         echo "($user) 1.0 i 9.0 i m s"
  120.         echo "(Request id: $JOBID) 1.0 i 8.5 i m s"
  121.         echo "(Copies: $NUMCOPIES) 1.0 i 8.0 i m s"
  122.         echo "(Options: $OPTIONS) 1.0 i 7.5 i m s"
  123.         echo "(Machine: $sysid) 1.0 i 7.0 i m s"
  124.         echo "(Date: $tdate) 1.0 i 6.5 i m s"
  125.         [ "$TITLE" ] && 
  126.             echo "(Title: $TITLE) 1.0 i 6.0 i m s"
  127.         echo "showpage"
  128.     
  129.         nhead=`expr $nhead - 1`
  130.     done  
  131. fi
  132. }
  133.  
  134.  
  135. # main()
  136.  
  137. #stty exta clocal hupcl cs8 cread icanon ixon icrnl 0<&1
  138. #stty exta -opost onlcr tab3 ixon -echo ixany -ixoff -parity -hupcl 0<&1
  139. #stty 9600 clocal hupcl cs8 cread icanon ixon ixoff icrnl 0<&1
  140. stty ixon ixoff 0<&1
  141.  
  142.  
  143. # print job defaults
  144. MODE=port  # print in portrait mode
  145. RAW=false  # process file as text file
  146.  
  147. PRTBANNER=true
  148. nhead=`sed -n 's/^BANNERS=//p' /etc/default/lpd`
  149. [ "$nhead" -eq 0 ] && PRTBANNER=false
  150.  
  151.  
  152. # DEBUG=true
  153. DEBUG=false
  154.  
  155. PRINTER=`basename $0`
  156.  
  157. $DEBUG && date >>/tmp/$PRINTER.out
  158. $DEBUG && echo "$*" >>/tmp/$PRINTER.out
  159.  
  160. JOBID="$1" ; shift
  161. $DEBUG && echo "JOBID is $JOBID" >>/tmp/$PRINTER.out
  162. USER="$1" ; shift
  163. $DEBUG && echo "USER is $USER" >>/tmp/$PRINTER.out
  164. TITLE="$1" ; shift
  165. $DEBUG && echo "TITLE is $TITLE" >>/tmp/$PRINTER.out
  166. NUMCOPIES="$1" ; shift
  167. [ "$NUMCOPIES" -lt 1 ] && NUMCOPIES=1
  168. $DEBUG && echo "NUMCOPS is $NUMCOPIES" >>/tmp/$PRINTER.out
  169. OPTIONS="$1" ; shift
  170. $DEBUG && echo "OPTIONS is $OPTIONS" >>/tmp/$PRINTER.out
  171. FILES="$*"
  172. $DEBUG && echo "FILES is $FILES" >>/tmp/$PRINTER.out
  173.  
  174.  
  175. for OPTION in $OPTIONS
  176. do
  177.     case $OPTION in
  178.         [Rr]aw | RAW | [Gg] )  RAW=true ;;
  179.         [Ll]and*2 | LAND*2 | [Ll]2 )  MODE=land2 ;;
  180.         [Ll]and* | LAND* | [Ll] )  MODE=land ;;
  181.         [Pp]ort* | PORT* | [Pp] )  MODE=port ;;
  182.       [Bb]an* | BAN* | [Bb] )     PRTBANNER=true ;;
  183.       [Nn]o[Bb]an | NOBAN* | [Nn][Bb] )   PRTBANNER=false ;;
  184.  
  185.         # these are tbr options
  186.         132 )    MODE=land ;;
  187.         sideways ) MODE=land ;;
  188.     esac
  189. done
  190. export MODE
  191.  
  192.  
  193. # the default text to postscript filter.
  194. TEXTFILTER=/usr/spool/lp/bin/text2post
  195.  
  196.  
  197. #Set up the default filter.
  198. if [  -x "${LOCALPATH}/lp.cat" ]
  199. then
  200.     LPCAT="${LOCALPATH}/lp.cat 0"
  201. else
  202.     LPCAT="cat"
  203. fi
  204.  
  205. #If we are not using an output filter, use the default one.
  206. [ -z "${FILTER}" ] && FILTER="${LPCAT}"
  207.  
  208.  
  209. # this all appears to support drain.output, which is not needed ???
  210. # ${SPOOLDIR:=/usr/spool/lp}
  211. # ${LOCALPATH:=${SPOOLDIR}/bin}
  212.  
  213. DRAIN=""
  214. [ -x "${LOCALPATH}/drain.output" ] && DRAIN="${LOCALPATH}/drain.output 1"
  215.  
  216.  
  217. echo "\004\c"                        # M003
  218.  
  219. $DEBUG && echo "FILTER is $FILTER" >>/tmp/$PRINTER.out
  220. $DEBUG && echo "TEXTFILTER is $TEXTFILTER" >>/tmp/$PRINTER.out
  221.  
  222. $PRTBANNER && PrintBannerPages
  223.  
  224.  
  225. i=1; FF=false
  226. while [ $i -le $NUMCOPIES ]
  227. do
  228.     for FILE in $FILES
  229.     do
  230.         PRINTRAW=$RAW
  231.         if FileIsPostscript $FILE
  232.         then
  233.             $DEBUG && echo "$FILE is a postscript file" >>/tmp/$PRINTER.out
  234.  
  235.             # switch the semantics on postscript files
  236.             # so -o raw prints the postscript code
  237.             PRINTRAW=true ; $RAW && PRINTRAW=false
  238.         fi
  239.             
  240.         if $PRINTRAW
  241.         then
  242.             $DEBUG && echo "Printing $FILE in raw mode" >>/tmp/$PRINTER.out
  243.             0<${FILE} eval ${FILTER} 2>&1
  244.         else
  245.             $DEBUG && echo "Printing $FILE in text mode" >>/tmp/$PRINTER.out
  246.             $FF && echo "\014"
  247.             0<${FILE} eval ${FILTER} 2>&1 | $TEXTFILTER
  248.         fi
  249.     done
  250.  
  251.     i=`expr $i + 1` ; FF=true
  252. done 
  253. echo "\004\c"                            # M003
  254.  
  255. #Draining characters might be necessary.
  256. ${DRAIN}
  257.  
  258. exit 0
  259.